# -*- coding: utf-8 -*-
"""
Embedding模块配置文件
"""

import os
from typing import Dict, Any

# 导入现有配置
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from common.config import LLM_CONFIG, USE_SILICONFLOW


class EmbeddingConfig:
    """Embedding配置类"""
    
    def __init__(self):
        # 复用现有LLM配置
        self.base_url = LLM_CONFIG["BASE_URL_dev"] if USE_SILICONFLOW else LLM_CONFIG["BASE_URL_1238"]
        self.model = LLM_CONFIG["MODEL_embedding"]
        self.api_key = LLM_CONFIG["API_KEY"] if USE_SILICONFLOW else None
        
        # Embedding专用配置
        self.timeout = 120
        self.max_retries = 3
        self.batch_size = 10  # 批量处理时的批次大小
        
        # 存储配置
        self.storage_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "embedding", "data")
        self.vector_file = os.path.join(self.storage_dir, "vectors.npy")
        self.metadata_file = os.path.join(self.storage_dir, "metadata.pkl")
        
        # 确保存储目录存在
        os.makedirs(self.storage_dir, exist_ok=True)
    
    def get_api_config(self) -> Dict[str, Any]:
        """获取API配置"""
        return {
            "base_url": self.base_url,
            "model": self.model,
            "api_key": self.api_key,
            "timeout": self.timeout
        }
    
    def get_storage_config(self) -> Dict[str, str]:
        """获取存储配置"""
        return {
            "storage_dir": self.storage_dir,
            "vector_file": self.vector_file,
            "metadata_file": self.metadata_file
        }


# 全局配置实例
embedding_config = EmbeddingConfig()
